<template>
  <ex-dialog width="800px" class="ex-diolog" :title="title" :visible="visible" :close-on-click-modal="false"
    @closeDialog="handleClose" append-to-body>
    <div class="main" v-loading="loading">
      <template>
        <el-form :model="ruleForm"  ref="ruleForm" :label-width="labelWidth" class="demo-ruleForm">
          <el-form-item label="直播日期：" prop="">{{ ruleForm.liveDate }}</el-form-item>
          <el-form-item label="直播客户：" prop="">{{ ruleForm.customerName }}</el-form-item>
          <el-form-item label="林客ID：" prop="">{{ ruleForm.linkId }}</el-form-item>
          <el-form-item label="可关联直播数据：" prop="liveIdList">
            <el-select v-model="ruleForm.liveIdList"  multiple placeholder="请选择" :style="{ width: inputWidth }">
              <el-option v-for="item in ruleForm.dataList" :key="item.liveId" :label="item.liveTime"
                :value="item.liveId"></el-option>
            </el-select>
          </el-form-item>

        </el-form>
      </template>
    </div>
    <div class="button_box" v-if="pathType != 'watch'">
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" :loading="AgreeLoading" @click="submitForm('ruleForm')">保存提交</el-button>
    </div>
  </ex-dialog>
</template>
<script>
import Loading from "@/components/Loading/index";
// api
import {
  getAssociation, postLiveId
} from "@/api/customer/serviceData";
export default {
  components: {
    Loading,
  },
  props: {
    visible: Boolean,
    id: String,
    pathType: String,
  },
  data() {
    return {
      labelWidth: "140px",
      inputWidth: "430px",
      title: "关联直播ID",
      loading: false,
      disabled: false,
      AgreeLoading: false,
      ruleForm: {
        id:'',
        liveDate:'',
        customerName:'',
        linkId:'',
        liveIdList:[],
        dataList:[],
      },
     
    };
  },
  computed: {},
  created() {
    console.log(this.pathType)
    this.getAssociation()
  },
  mounted() {

  },
  computed: {},
  methods: {
    //获取详情
    getAssociation() {
      getAssociation(this.id).then(res => {
        this.ruleForm = res.result
        
      })
    },
    //取消
    handleClose(formName) {
      this.$emit("update:visible", false);
    },
    submitForm(formName) {
      //创建确定
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.AgreeLoading = true
          var data = {
            ...this.ruleForm
          }
          postLiveId(data).then(res => {
            this.handleClose()
            this.$message.success('操作成功')
            this.$emit('success')
            this.AgreeLoading = false
          }).catch(() => {
            this.AgreeLoading = false
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  }
};
</script>
<style lang="scss" scoped>
.ex-diolog {
  ::v-deep .ex--dialog--footer {
    border: none !important;
    padding: 0 !important;
  }

  ::v-deep .ex--dialog--main {
    padding: 10px 20px !important;
  }
}

.el-select,
.el-input,
.el-cascader {
  width: 400px;
}

.main {
  padding: 20px 20px;
}

.button_box {
  display: flex;
  justify-content: center;
}

.el-radio-group {
  display: flex;
  flex-direction: column;

  .el-radio {
    margin-bottom: 14px;
  }
}

.form_item {
  display: flex;
}

.form_item_label {
  margin-left: 18px;
  color: #606266;
  font-size: 14px;
  font-weight: bold;
}

.form_item_detail {
  margin-left: 10px;
}
</style>